﻿using AndoridMoeTool.AndroidTool.SDK.Media;
using CatUtils.Utils.Currency;
using CatUtils.Utils.Currency.IoUtils;
using CatUtils.Utils.Currency.TextUtils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PictureCompression.UserUtils
{
    internal class UserImageHelper
    {
        public static void SaveFileBatch(List<string> FilePath, string FileSizeText, string TipFloder)
        {
            foreach (var item in FilePath)
            {
                SaveFile(item, FileSizeText, TipFloder);
            }
        }

        public static string SaveFile(string FilePath, string FileSizeText, string TipFloder)
        {
            Console.WriteLine(FilePath);
            int FileSize = TextHelper.StringToInt(FileSizeText);
            if (FileSize == 0)
                return FilePath;

            string FileType = FileNameHelper.GetFileType(FilePath);
            List<string> FileTypteList = new List<string>() { ".jpg", ".jpeg", ".png", ".bmp", ".JPG", ".PNG" };
            if (!ListHelper.CompareRepetition(FileType, FileTypteList))
            {
                Console.WriteLine($"文件类型{FileType}无法处理，跳过！");
                return FilePath;
            }
            TipFloder = TextHelper.ReplaceBadChar(TipFloder);
            return new MagickImageHelper().ImgResizeToFileSize(FilePath, 190, TipFloder);
        }
    }
}